package v9.assist.analyst

import android.graphics.Bitmap
import kotlinx.coroutines.script.Block
import kotlinx.coroutines.script.TARGET
import kotlinx.coroutines.script.analysis.Analysis
import kotlinx.coroutines.script.SMapBase.hitDeathRed
import kotlinx.coroutines.script.SMapBase.hitEquipO
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyBlue
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyYellow
import kotlinx.coroutines.script.SMapBase.hitTeammate
import kotlinx.coroutines.script.tes.ColorDiffer
import kotlinx.coroutines.script.tes.printLog
import kotlinx.coroutines.script.tes.pt
import kotlinx.coroutines.script.tes.rgb
import kotlinx.coroutines.script.tes.shake
import v9.assist.script.sLastFeature30Ts
import v9.assist.script.xBossBesideTs
import v9.assist.script.xLastAtkTs
import v9.assist.script.xLastPetBlacksmithTs
import v9.assist.script.xLastSceneEnterTs
import v9.assist.script.xLastUnknownTs
import kotlin.math.abs

private val hitRoadByStart by lazy {
    val out = mutableSetOf<ColorDiffer>()
    out.addAll(setOf(0xff624F3E.toInt().rgb(16),)) //p1 最最最起点
    out.addAll(setOf(0xff534b40.toInt().rgb(16),)) //p1 悬崖树枝
    out.addAll(hitRoad)
    out
}

private val hitRoad by lazy {
    val out = mutableSetOf<ColorDiffer>()

    out.addAll(setOf(0xff36332B.toInt().rgb(8),)) //p1 起点
    out.addAll(setOf(0xff3F382C.toInt().rgb(8),)) //p1 起点
    out.addAll(setOf(0xff4a4136.toInt().rgb(8),)) //p1 road
    out.addAll(setOf(0xff534b40.toInt().rgb(8),)) //p1 悬崖树枝
    out.addAll(setOf(0xff3F3C35.toInt().rgb(8),)) //p1 悬崖下
    out.addAll(setOf(0xffF4BD63.toInt().rgb(8),)) //火焰 黄
    out.addAll(setOf(0xff9C331E.toInt().rgb(8),)) //火焰 红
    out.addAll(setOf(0xff53332B.toInt().rgb(6),)) //火焰 road

    out.addAll(hitEquipO)
    out.addAll(hitDeathRed)
    out.addAll(hitTeammate)
    out.addAll(hitSMapEnemyYellow)
    out.addAll(hitSMapEnemyBlue)
    out
}

var anaLastSMapHMFeature1Ts = 0L // 副本起点B
var anaLastSMapHMFeature2Ts = 0L // 副本起点A 一进门
var anaLastSMapHMFeature14Ts = 0L // 交叉口.[扩大左上角]
var anaLastSMapHMFeature3Ts = 0L // Boss前小道
var anaLastSMapHMFeature4Ts = 0L // 副本外面
var anaLastSMapHMFeature6Ts = 0L // Boss1阶段击破右侧悬崖树
var anaLastSMapHMFeature8Ts = 0L // 副本外面右侧
var anaLastSMapHMFeature9Ts = 0L // 最终Boss前小路卡住
var anaLastSMapHMFeature10Ts = 0L // Boss前小道B
var anaLastSMapHMFeature11Ts = 0L // Boss1阶段击破卡左下坑
var anaLastSMapHMFeature12Ts = 0L // 恶魔督军
var anaLastSMapHMFeature13Ts = 0L // 起点漏小怪

fun rasterizeMapHM(ss: Bitmap) : Array<IntArray>{
    // 踢掉黄色敌人.是火焰
    val analysisHitRoad = if (System.currentTimeMillis() - lastBlueDoorTs < 2000) hitRoadByStart else hitRoad
    return rasterizeMap(ss, analysisHitRoad, emptyPrimaryRoad, filterEnemyY = true, filterRedDot = false)
}

fun analysisMapHM(ss: Bitmap) {
    analysisMapElements(ss)
    val returnMapArray = rasterizeMapHM(ss)

    if (blockEliteEnemyBoss != null && mapEnemyList.isNotEmpty()) {
        // 优先Boss
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to boss" }
        lastSMapTargetToBossTs = System.currentTimeMillis()
        if (mapElementDistance(blockEliteEnemyBoss) < 30.pt) xBossBesideTs = System.currentTimeMillis()
    } else if (mapNpcList.isNotEmpty()
        && System.currentTimeMillis() - xLastAtkTs > 10000) {
        mapTargetList.add(mapNpcList.random())
        lastSMapTargetToNpcTs = System.currentTimeMillis()
        printLog { "analyst target to npc by no atk [$lastSMapTargetToNpcDs]" }
    } else if (mapEnemyList.isNotEmpty()
        && System.currentTimeMillis() - anaLastSMapHMFeature4Ts > 10000 // 在副本外面的误判导致没有开始
        && System.currentTimeMillis() - anaLastSMapHMFeature8Ts > 10000
        && System.currentTimeMillis() - anaLastPageSceneEnterTs > 10000 // 刚开局就需要
        && System.currentTimeMillis() - anaLastSceneSettleTs > 20000
        && System.currentTimeMillis() - xLastUnknownTs > 10000
        && !bsSceneSettle && !bsSceneSettleBlacksmith) {
        // 优先敌人
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to elite enemy" }
    } else if (bsSceneSettleBlacksmith && mapBlacksmithList.isNotEmpty()) {
        mapTargetList.add(mapBlacksmithList.random())
        printLog { "analyst target to blacksmith" }
    } else if (bsSceneSettle && mapBlueDoorList.isNotEmpty()) {
        mapTargetList.add(mapBlueDoorList.random())
        printLog { "analyst target to blueDoor" }
    } else if (mapNpcList.isNotEmpty()) {
        mapTargetList.add(mapNpcList.random())
        lastSMapTargetToNpcTs = System.currentTimeMillis()
        printLog { "analyst target to npc" }
    } else if (mapRightNotArrived.size > 0) {
        mapTargetList.add(mapRightNotArrived.random())
        printLog { "analyst target to right" }
    } else if (mapTopNotArrived.size > 0) {
        (mapTopNotArrived.maxByOrNull { it.first } ?: mapTopNotArrived.random()).also {
            mapTargetList.add(it)
            printLog { "analyst target to top right" }
        }
    } else if (mapBottomNotArrived.size > 0
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        && System.currentTimeMillis() - anaLastSMapHMFeature3Ts > 36000
        && System.currentTimeMillis() - anaLastSMapHMFeature10Ts > 36000
        && System.currentTimeMillis() - anaLastSMapHMFeature12Ts > 36000) {
        (mapBottomNotArrived.maxByOrNull { it.first } ?: mapBottomNotArrived.random()).also {
            mapTargetList.add(it)
            printLog { "analyst target to bottom right" }
        }
    } else if (mapSampleArrived.size > 0) {
        mapSampleArrived
            .filter { it.first > selfInSmallMap.x - smallMap.left && it.second < selfInSmallMap.y - smallMap.top }
            .randomOrNull()?.also {
                mapTargetList.add(it)
                printLog { "analyst target to sample top right " }
            }
    }

    if (mapTargetList.isNotEmpty()) {
        val target = mapTargetList.random()
        returnMapArray[target.first][target.second] = TARGET
    }

    angleByRoad = analysisRasterizeMap(returnMapArray)
    angleByRoad = angleSpecialAdjust(angleByRoad ?: 90.shake(20))

    // map feature
    analysisMapHMIsStartPoint(ss)
    if ((blockBlueDoor == null || blockBlacksmith == null)
//      毁灭boss前还有个小路要判断.卡住了需要往上走 && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
    ) {
         printLog { "analystHM $mapSimpleStatus" }
        if (
//            System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
//            && (lastMapTopP ?: -1f) in 0.66 .. 0.76
            && (lastMapBottomP ?: -1f) in 0.41 .. 0.61
            && (lastMapLeftP ?: -1f) in 0.26 .. 0.46
            && lastMapRightP == null
            && System.currentTimeMillis() - lastSMapTargetToNpcTs > 4000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 4000
        ) {
            // [上,1737704149s,c:0][下,0s,0.44915253,c:12][左,0s,0.44871795,c:18][右,1737704149s,c:0]][Road,c:13]
            // [上,41s,c:0][下,0s,0.42912173,c:11][左,0s,0.38846153,c:20][右,1737703971s,c:0]][Road,c:14]
            // [上,0s,0.71307504,c:7][下,0s,0.5685499,c:15][左,0s,0.32905984,c:32][右,142s,c:0]][Road,c:38]
            // [上,1737704176s,c:0][下,0s,0.46986815,c:9][左,0s,0.41632926,c:19][右,1737704176s,c:0]][Road,c:14]
            printLog { "analystHM 节点.交叉口" }
            anaLastSMapHMFeature14Ts = System.currentTimeMillis()
        } else if (
            System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapBottomP ?: -1f) in 0.01 .. 0.11
            && (lastMapLeftP ?: -1f) in 0.81 .. 0.91
            && (lastMapRightP ?: -1f) in 0.31 .. 0.41
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 15000
            && System.currentTimeMillis() - lastBlueDoorTs > 3000
        ) {
            printLog { "analystHM 节点.恶魔督军" }
            // [上,4s,c:0][下,0s,0.045415036,c:13][左,0s,0.86752135,c:20][右,0s,0.34615386,c:11]][Road,c:17]
            // [上,0s,0.9745763,c:1][下,0s,0.054378532,c:16][左,0s,0.87606835,c:18][右,0s,0.3850039,c:11]][Road,c:18]
            // [上,0s,c:0][下,0s,0.045415036,c:13][左,0s,0.86223036,c:21][右,0s,0.37179488,c:8]][Road,c:18]
            anaLastSMapHMFeature12Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && (lastMapTopP ?: -1f) in 0.66 .. 0.76
            && (lastMapBottomP ?: -1f) in 0.28 .. 0.38
            && lastMapLeftP == null
            && lastMapRightP == null
        ) {
            // [上,0s,0.71468925,c:1][下,0s,0.33875403,c:37][左,1737647602s,c:0][右,37s,c:0]][Road,c:20]
            printLog { "analystHM 节点.Boss前小道" }
            anaLastSMapHMFeature3Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && (lastMapBottomP ?: -1f) in 0.12 .. 0.24
            && lastMapBottomC in 4 .. 20
            && lastMapLeftP == null
            && System.currentTimeMillis() - lastBlueDoorTs > 12000
            && System.currentTimeMillis() - anaLastSMapHMFeature6Ts > 12000
        ) {
            // [上,100s,c:0][下,0s,0.44738007,c:102][左,0s,0.5985079,c:59][右,0s,0.6780627,c:45]][Road,c:79]
            // [上,0s,0.84274954,c:6][下,0s,0.1866975,c:11][左,96s,c:0][右,0s,0.14102565,c:6]][Road,c:20]
            // [上,0s,0.9858757,c:1][下,0s,0.19572236,c:14][左,121s,c:0][右,0s,0.111396015,c:15]][Road,c:25]
            // [上,17s,c:0][下,0s,0.19491525,c:10][左,142s,c:0][右,0s,0.115384616,c:14]][Road,c:22]
            printLog { "analystHM 节点.Boss前小道B" }
            anaLastSMapHMFeature10Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.64 .. 0.80
            && (lastMapBottomP ?: -1f) in 0.40 .. 0.60
            && (lastMapLeftP ?: -1f) in 0.70 .. 0.90
            && (lastMapRightP ?: -1f) in 0.12 .. 0.32
            && System.currentTimeMillis() - lastBlueDoorTs > 5000
            && System.currentTimeMillis() - lastSMapTargetToNpcTs > 5000
        ) {
            // [上,0s,0.7761472,c:41][下,0s,0.4989109,c:83][左,0s,0.79663146,c:34][右,0s,0.22649573,c:1]][Road,c:40]
            printLog { "analystHM 节点.副本外入口" }
            anaLastSMapHMFeature4Ts = System.currentTimeMillis()
            anaClearSceneSettle() // [重要.结算失败.角色跑出去了]重置掉结算状态
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
//            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && lastMapTopP == null
//            && (lastMapBottomP ?: -1f) in 0.20 .. 0.48
            && (lastMapLeftP ?: -1f) in 0.38 .. 0.88
            && lastMapRightP == null
            && System.currentTimeMillis() - lastBlueDoorTs > 20000
            && System.currentTimeMillis() - lastSMapTargetToNpcTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 5000
            && System.currentTimeMillis() - xLastAtkTs > 5000
            && System.currentTimeMillis() - lastBlueDoorTs > 5000
            && System.currentTimeMillis() - lastBlacksmithTs > 5000
            && !bsSceneSettle && !bsSceneSettleBlacksmith
        ) {
            // [上,85s,c:0][下,0s,0.2974031,c:57][左,0s,0.7284382,c:22][右,42s,c:0]][Road,c:9]
            // [上,71s,c:0][下,0s,0.19386901,c:27][左,0s,0.63461536,c:32][右,28s,c:0]][Road,c:8]
            // [上,160s,c:0][下,0s,0.28413814,c:53][左,0s,0.73646724,c:27][右,114s,c:0]][Road,c:11]
            // [上,30s,c:0][下,0s,0.3558694,c:90][左,0s,0.7540792,c:44][右,233s,c:0]][Road,c:31]
            // 2400p [上,228s,c:0][下,0s,0.38680914,c:115][左,0s,0.72859055,c:51][右,15s,c:0]][Road,c:33]
            // 2400p [上,112s,c:0][下,0s,0.41381788,c:118][左,0s,0.73646724,c:48][右,20s,c:0]][Road,c:33]
            //  [上,48s,c:0][下,0s,0.33102208,c:55][左,0s,0.6905666,c:27][右,43s,c:0]][Road,c:21]
            // [上,80s,c:0][下,0s,0.31979534,c:53][左,0s,0.713141,c:24][右,80s,c:0]][Road,c:17]
            //  [上,1742225251s,c:0][下,0s,0.07980226,c:12][左,0s,0.70310396,c:19][右,1742225251s,c:0]][Road,c:12]
            printLog { "analystHM 节点.Boss1阶段击破右侧悬崖树" }
            anaLastSMapHMFeature6Ts = System.currentTimeMillis()
        } else if (
//            System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
             System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
//            && lastMapTopP == null
            && lastMapBottomP == null
            && (lastMapLeftP ?: -1f) in 0.60 .. 0.72
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 15000
            && System.currentTimeMillis() - lastBlueDoorTs > 3000
            && System.currentTimeMillis() - xLastAtkTs > 20000
            && System.currentTimeMillis() - anaLastHasEnemyBossNameTs > 30000
        ) {
            printLog { "analystHM 节点.最终Boss前小路卡住" }
            // [上,1738034600s,c:0][下,1738034600s,c:0][左,0s,0.66239315,c:16][右,0s,0.29145297,c:5]][Road,c:21]
            // [上,1738034621s,c:0][下,1738034621s,c:0][左,0s,0.66239315,c:16][右,0s,0.29145297,c:5]][Road,c:21]
            // [上,1738034631s,c:0][下,1738034631s,c:0][左,0s,0.6637427,c:19][右,0s,0.29145297,c:5]][Road,c:21]
            // [上,0s,0.96214694,c:10][下,1738035036s,c:0][左,0s,0.74817985,c:27][右,0s,0.19551282,c:32]][Road,c:23]
            anaLastSMapHMFeature9Ts = System.currentTimeMillis()
        } else if (
            System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && lastMapTopP == null
            && (lastMapBottomP ?: -1f) in 0.25 .. 0.40
            && (lastMapLeftP ?: -1f) in 0.24 .. 0.38
            && lastMapRightP == null
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 15000
            && System.currentTimeMillis() - lastBlueDoorTs > 3000
            && System.currentTimeMillis() - xLastAtkTs > 6000
        ) {
            printLog { "analystHM 节点.Boss1阶段击破去交叉点卡左下坑" }
            // [上,58s,c:0][下,0s,0.31612736,c:11][左,0s,0.29046044,c:31][右,15s,c:0]][Road,c:28]
            // [上,76s,c:0][下,0s,0.33920035,c:13][左,0s,0.32051283,c:30][右,33s,c:0]][Road,c:33]
            anaLastSMapHMFeature11Ts = System.currentTimeMillis()
        } else if (
            System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && (lastMapRightP ?: -1f) in 0.26 .. 0.38
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 30000
            && System.currentTimeMillis() - lastBlueDoorTs < 2000
            && System.currentTimeMillis() - xLastAtkTs > 24000
            && System.currentTimeMillis() - lastSMapTargetToNpcTs < 1000
        ) {
            printLog { "analystHM 节点.起点漏小怪" }
            // [上,80s,c:0][下,1s,c:0][左,86s,c:0][右,0s,0.30876067,c:32]][Road,c:33]
            // [上,89s,c:0][下,1s,c:0][左,94s,c:0][右,0s,0.3315018,c:35]][Road,c:30]
            // [上,108s,c:0][下,0s,0.181237,c:19][左,0s,0.814267,c:13][右,0s,0.3070818,c:28]][Road,c:38]
            anaLastSMapHMFeature13Ts = System.currentTimeMillis()
        }

    }


    if (System.currentTimeMillis() - anaLastPageSceneEnterTs > 8000
        && System.currentTimeMillis() - xLastUnknownTs > 6000
        && System.currentTimeMillis() - anaLastHasEnemyNameTs > 4000
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 4000
        && blockBlueDoor != null
        && blockBlacksmith != null
        && !bsSceneSettle && !bsSceneSettleBlacksmith
        && simpleAssertSceneCompleted(blockBlueDoor, blockBlacksmith)
        // 开局有误判
        && System.currentTimeMillis() - lastSMapTargetToNpcTs > 2000
        && System.currentTimeMillis() - lastMapTopNotArrivedTs > 6000 // 顶部无路.屏蔽开局
        && System.currentTimeMillis() - lastMapRightNotArrivedTs > 6000 // 右侧无路.屏蔽开局 确认是终点. 有时候跳崖就误判了
        ) {
        printLog { "analyst scene completed count $anaCounterSceneSettle" }
        anaCounterSceneSettle++
        if (anaCounterSceneSettle > 0) {
            printLog { "analyst scene completed" }
            anaMarkSceneSettle()
        }
    }
    if (System.currentTimeMillis() - lastBlueDoorTs > 3000
        && System.currentTimeMillis() - lastBlacksmithTs > 3000) {
        anaCounterSceneSettle = 0
    }
}

private val cHMP1StartA1 by lazy { Block("毁灭起点检测左outA1", selfInSmallMap.x - 30.pt, selfInSmallMap.y + 30.pt, 20.pt, 20.pt) }
private val cHMP1StartA2 by lazy { Block("毁灭起点检测左outA2", selfInSmallMap.x - 30.pt, selfInSmallMap.y + 0.pt, 20.pt, 20.pt) }
private val cHMP1StartA3 by lazy { Block("毁灭起点检测左outA3", selfInSmallMap.x - 30.pt, selfInSmallMap.y - 30.pt, 20.pt, 20.pt) }
private val cHMP1StartA4 by lazy { Block("毁灭起点检测右outB1", selfInSmallMap.x + 20.pt, selfInSmallMap.y - 30.pt, 20.pt, 20.pt) }
private val cHMP1StartA5 by lazy { Block("毁灭起点检测右outB2", selfInSmallMap.x + 20.pt, selfInSmallMap.y + 10.pt, 20.pt, 20.pt) }
private val cHMP1StartA6 by lazy { Block("毁灭起点检测上outC1", selfInSmallMap.x - 10.pt, selfInSmallMap.y - 80.pt, 20.pt, 20.pt) }
private val cHMP1StartA7 by lazy { Block("毁灭起点路", selfInSmallMap.x - 5.pt, selfInSmallMap.y - 55.pt, 20.pt, 30.pt) }
private val hitStartRoad by lazy { setOf(0xff343028.toInt().rgb(6),) }
val cHMP1StartA8 by lazy { Block("毁灭火路", selfInSmallMap.x + 140.pt, selfInSmallMap.y - 60.pt, 15.pt, 30.pt) }
val hitStartFire by lazy {
    setOf(
        0xffF4BD6C.toInt().rgb(20),
        0xffBB6438.toInt().rgb(20),
    )
}


fun analysisMapHMIsStartPoint(ss: Bitmap): Boolean {
//    printLog { "analysisMapHMIsStartPoint analystHM $mapSimpleStatus" }
    if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
         && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
         && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
         && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
         && blockBlacksmith == null) {
        var hitPart = 0
        // hit [cHMP1StartA7] 0.7708333 hitCount 37 total 48
        // hit [hitStartFire] 0.25 hitCount 8 total 32
        if (!Analysis.hit(ss, cHMP1StartA1, hitStartRoad, 4.pt, 0.1f,)) hitPart++ // , "hmP1"
        if (!Analysis.hit(ss, cHMP1StartA2, hitStartRoad, 4.pt, 0.1f,)) hitPart++ // , "hmP2"
        if (!Analysis.hit(ss, cHMP1StartA3, hitStartRoad, 4.pt, 0.1f,)) hitPart++ // , "hmP3"
        if (!Analysis.hit(ss, cHMP1StartA4, hitStartRoad, 4.pt, 0.1f,)) hitPart++ //  "hmP4"
        if (!Analysis.hit(ss, cHMP1StartA5, hitStartRoad, 4.pt, 0.1f,)) hitPart++ // , "hmP5"
        if (!Analysis.hit(ss, cHMP1StartA6, hitStartRoad, 4.pt, 0.1f,)) hitPart++ // , "hmP6"
        if (Analysis.hit(ss, cHMP1StartA7, hitStartRoad, 4.pt, 0.6f, )) hitPart++ // , "hmP7"
        if (Analysis.hit(ss, cHMP1StartA8, hitStartFire, 4.pt, 0.16f, )) hitPart++ // , "hmP8"
        if (hitPart >= 8) {
            printLog { "analystHM 节点.毁灭副本起点B" }
            anaLastSMapHMFeature1Ts = System.currentTimeMillis()
            anaClearSceneSettle()
            return true
        }
    }

    if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
        && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
        && (lastMapTopP ?: -1f) in 0.74 .. 0.82
        && lastMapTopC in 12 .. 32
        && lastMapBottomP == null
        && lastMapLeftP == null
        && (lastMapRightP ?: -1f) in 0.10 .. 0.18
        && lastMapRightC in 1 .. 15
        && blockBlacksmith == null
        // && System.currentTimeMillis() - lastBlueDoorTs < 3000
    ) {
        // [上,0s,0.7932472,c:21][下,1748860497s,c:0][左,1748860497s,c:0][右,0s,0.12148962,c:7]][Road,c:12]
        // [上,0s,0.78954804,c:20][下,1746151874s,c:0][左,1746151874s,c:0][右,0s,0.15201466,c:7]][Road,c:10]
        printLog { "analystHM 节点.毁灭副本起点A" }
        anaLastSMapHMFeature2Ts = System.currentTimeMillis()
        anaClearSceneSettle()
        return true
    }
    return false
}

private fun simpleAssertSceneCompleted(blueDoor: Block?, blacksmith: Block?): Boolean {
    if (blueDoor == null) return false
    if (blacksmith == null) return false
    val edge = 80.pt
    return abs(blueDoor.x - blacksmith.x) < edge && abs(blueDoor.y - blacksmith.y) < edge
}

private fun angleSpecialAdjust(angle: Int): Int {

    if (System.currentTimeMillis() - anaLastHasEnemyBossNameTs > 3000
        && System.currentTimeMillis() - lastEliteEnemyTs > 3000
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 3000
        && System.currentTimeMillis() - xLastAtkTs < 600
        && System.currentTimeMillis() - sLastFeature30Ts > 1600) {
        printLog { "analystHM 回撤清理漏怪" }
        sLastFeature30Ts = System.currentTimeMillis()
        return (angle + 180) % 360
    }

    if (angle in 10 .. 280) {
        if (System.currentTimeMillis() - xLastAtkTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyTs > 5000
            && System.currentTimeMillis() - anaLastSMapHMFeature1Ts > 20000 // 地图特征 条件
            && System.currentTimeMillis() - anaLastSMapHMFeature14Ts > 20000
            && System.currentTimeMillis() - xLastUnknownTs < 20000
            && System.currentTimeMillis() - xLastSceneEnterTs > 30000
            && System.currentTimeMillis() - anaLastPageTalkNpcTs > 20000
            && System.currentTimeMillis() - lastSMapTargetToNpcTs > 20000  // 毁灭特有a 因为开局就跳崖触发unknown
            && System.currentTimeMillis() - xLastPetBlacksmithTs > 20000
            && System.currentTimeMillis() - anaLastSMapHMFeature2Ts > 20000) { // 毁灭特有b
            printLog { "analystHM angleSpecialAdjust $angle to 320" }
            return 320
        }
    }
    return angle
}